package kr.hkit.powerjava.alone.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.alone.dao.BankInterfaceDao;
import kr.hkit.powerjava.alone.vo.User;

public class UserService extends ServiceItem<User> {

	public UserService(BankInterfaceDao<User> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public User inputItemInfo(boolean gubun) {
		System.out.println("번호 이름");
		User use = new User(sc.nextInt(), sc.next().trim());

		if (gubun) {
			System.out.println("도시");
			String city = sc.next();
			use.setCity(city);
		}

		return use;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1.이름순 2.도시순 3.번호순");
		int res = sc.nextInt();
		switch (res) {
		case 1:
			dao.prnItemList(new Comparator<User>() {

				@Override
				public int compare(User o1, User o2) {
					return o1.getUserName().hashCode()
							- o2.getUserName().hashCode();
				}
			});
			break;

		case 2:
			dao.prnItemList(new Comparator<User>() {

				@Override
				public int compare(User o1, User o2) {
					return o1.getCity().hashCode() - o2.getCity().hashCode();
				}
			});
			break;
		default:
			dao.prnItemList(null);
		}
	}

}
